@extends('layouts.app')
@include('good.sidebar')
@section('content')
@php
    use Illuminate\Support\Facades\Auth;
    use App\Modules\User\Models\Admin;
    $user = Auth::user();
@endphp
    <div class="content">
        <div class="row custom-invoice">
            <div class="row">
                <form method="get" action="{{ route('admin.tag.index') }}">
                    <input name="shop_id" value="{{ $shopId }}" type="hidden"/>
                    
                    <div class="form-group col-md-2 col-sm-6 col-xs-10" style="width:250px">
                        <input class="form-control" type="text" name="name" value="{{ $name }}" placeholder="名称">
                    </div>
                    <div class="form-group col-md-2 col-sm-10 col-xs-10" style="width:100px">
                        <button class="btn btn-success btn-ms" type="submit">搜索</button>
                    </div>
                </form>
            </div>
            
            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                @can('staff_tag')
                    <a class="btn btn-success" href="{{ route("admin.tag.create", ['shop_id' => $shopId]) }}">添加</a>
                @endcan
            @else
                @can('tag-add')
                    <a class="btn btn-success" href="{{ route("admin.tag.create", ['shop_id' => $shopId]) }}">添加</a>
                @endcan
            @endif
            <br />
            <br />
            <table class="table table-striped table-hover">
                <thead>
                <tr>
                    <th style="width:250px">服务名称</th>
                    <!-- <th style="width:100px">图标</th> -->
                    <th style="width:400px">描述</th>
                    <th style="width:250px">操作</th>
                    <th style="width:250px">排序权重</th>
                </tr>
                </thead>
                <tbody>
                @foreach($data as $item)
                    <tr>
                        <td>{{ $item->name }}</td>
                        <!-- <td>
                           <img src="{{ \App\Library\OSS::instance()->getUrl($item->icon) }}" width="100">
                        </td> -->
                        <td>{{ $item->describe }}</td>
                        <td>
                            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                @can('staff_tag-edit')
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.tag.edit', ['tag' => $item, 'shop_id' => $shopId]) }}"><i class="fa fa-edit"></i> 编辑</a>
                                @endcan
                            @else
                                @can("tag-edit")
                                    <a class="btn btn-primary btn-xs" href="{{ route('admin.tag.edit', ['tag' => $item, 'shop_id' => $shopId]) }}"><i class="fa fa-edit"></i> 编辑</a>
                                @endcan
                            @endif
                            @if($user->is_merchant_staff == Admin::MERCHANT_AUTH)
                                @can('staff_tag-del')
                                    <a class="btn btn-danger btn-xs delete-confirm" data-href="{{ route('admin.tag.destroy', ['tag' => $item]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                                @endcan
                            @else
                                @can("tag-del")
                                    <a class="btn btn-danger btn-xs delete-confirm" data-href="{{ route('admin.tag.destroy', ['tag' => $item]) }}"><i class="fa fa-trash-o"></i> 删除</a>
                                @endcan
                            @endif
                            
                            
                        </td>
                        <td>
                            <input type="text" class="col-xs-5 change-sort" data-id="{{ $item->id }}" value="{{ $item->sort }}" />
                        </td>
                    </tr>
                @endforeach
                </tbody>
            </table>
            {{ $data->links() }}
        </div>
    </div>
@endsection
@push('scripts')
    <script>
        $('.change-sort').on('change', function () {
            var sort = $(this).val();
            var id = $(this).attr('data-id');
            $.ajax({
                url: '{{ route('admin.tag.sort') }}',
                type: "GET",
                dataType:'json',
                data: {
                    id: id,
                    sort: sort,
                },
                success: function (re) {
                }
            });
        });

    </script>
@endpush
